package com.ftf.tp.blog.interfaces.controller;


import com.ftf.tp.blog.application.dto.ArticleCommentDTO;
import com.ftf.tp.blog.application.dto.ArticleCommentPageDTO;
import com.ftf.tp.blog.application.dto.ArticleCommentReplyPageDTO;
import com.ftf.tp.blog.application.service.command.CommentCommandService;
import com.ftf.tp.blog.application.vo.ArticleCommentVO;
import com.ftf.tp.common.core.annotation.ResponseResult;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文章评论controller
 *
 * @author tanghao
 * @date 2021/12/20
 */
@RestController
@ResponseResult
@RequestMapping("/blog/blogComment")
@Api
public class ArticleCommentController {

    @Resource
    private CommentCommandService commentCommandService;

    /**
     * 评论文章
     *
     * @param blogComment 评论dto
     */
    @PostMapping("/auth/publishComment")
    public void publishComment(@RequestBody ArticleCommentDTO blogComment) {
        commentCommandService.publishComment(blogComment);
    }


    /**
     * 分页获取文章评论
     *
     * @param articleCommentPageDTO 文章评论分页参数
     */
    @PostMapping("/getCommentByBlogId")
    public List<ArticleCommentVO> getCommentByBlogId(@RequestBody ArticleCommentPageDTO articleCommentPageDTO) {
        return commentCommandService.getCommentByBlogId(articleCommentPageDTO);
    }


    /**
     * 查看评论的所有回复
     *
     * @param articleCommentReplyPageDTO 文章回复分页参数
     */
    @PostMapping("/getReplyByCommentId")
    public List<ArticleCommentVO> getReplyByCommentId(@RequestBody ArticleCommentReplyPageDTO articleCommentReplyPageDTO) {
        return commentCommandService.getReplyByCommentId(articleCommentReplyPageDTO);
    }

    /**
     * 删除当前评论
     *
     * @param commentId   评论id
     * @param commentType 类型
     */
    @PostMapping("/deleteCommentById")
    public void deleteCommentById(@RequestParam("commentId") Long commentId,@RequestParam("commentType") Integer commentType) {
        commentCommandService.deleteCommentById(commentId,commentType);
    }


}
